package com.blrs.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.blrs.common.core.page.PageDomain;
import com.blrs.common.core.page.TableSupport;
import com.blrs.common.utils.page.PaginationUtil;
import com.blrs.domain.PolicyRelease;
import com.blrs.service.product.IProductReleaseService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.blrs.common.annotation.Log;
import com.blrs.common.core.controller.BaseController;
import com.blrs.common.core.domain.AjaxResult;
import com.blrs.common.enums.BusinessType;
import com.blrs.domain.ProductRelease;
import com.blrs.common.utils.poi.ExcelUtil;
import com.blrs.common.core.page.TableDataInfo;

/**
 * 产品发布Controller
 * 
 * @author ruoyi
 * @date 2024-01-10
 */
@RestController
@RequestMapping("/product/release")
public class ProductReleaseController extends BaseController
{
    @Autowired
    private IProductReleaseService productReleaseService;

    /**
     * 查询产品发布列表
     */
    @GetMapping("/list")
    public TableDataInfo list(ProductRelease productRelease)
    {
        startPage();
        List<ProductRelease> list = productReleaseService.selectProductReleaseList(productRelease);
        return getDataTable(list);
    }

    /**
     * 导出产品发布列表
     */
    @Log(title = "产品发布", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ProductRelease productRelease)
    {
        List<ProductRelease> list = productReleaseService.selectProductReleaseList(productRelease);
        ExcelUtil<ProductRelease> util = new ExcelUtil<ProductRelease>(ProductRelease.class);
        util.exportExcel(response, list, "产品发布数据");
    }

    /**
     * 获取产品发布详细信息
     */
    @GetMapping(value = "/{productId}")
    public AjaxResult getInfo(@PathVariable("productId") String productId)
    {
        return success(productReleaseService.selectProductReleaseByProductId(productId));
    }

    /**
     * 新增产品发布
     */
    @Log(title = "产品发布", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProductRelease productRelease) throws NoSuchFieldException, IllegalAccessException {
        return toAjax(productReleaseService.insertProductRelease(productRelease));
    }

    /**
     * 修改产品发布
     */
    @Log(title = "产品发布", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProductRelease productRelease)
    {
        return toAjax(productReleaseService.updateProductRelease(productRelease));
    }

    /**
     * 删除产品发布
     */
    @Log(title = "产品发布", businessType = BusinessType.DELETE)
	@DeleteMapping("/{productIds}")
    public AjaxResult remove(@PathVariable String[] productIds)
    {
        return toAjax(productReleaseService.deleteProductReleaseByProductIds(productIds));
    }

    /**
     * 查看待产品发布信息
     */
    @GetMapping("/examineList")
    public TableDataInfo examineList(ProductRelease productRelease)
    {
        startPage();
        List<ProductRelease> list = productReleaseService.selectProductReleaseListByExamine(productRelease);
        return getDataTable(list);
    }
    /**
     * 审核产品发布信息
     */
    @GetMapping("/examine/{id}")
    public AjaxResult  process(@PathVariable String id)
    {
        return toAjax(productReleaseService.updateProductReleaseByStatus(id));
    }

    /**
     * 接收方产品发布信息列表
     */
    @GetMapping("/receive")
    public TableDataInfo receiveList(ProductRelease productRelease)
    {
        startPage();
        List<ProductRelease> list = productReleaseService.selectProductReleaseListReceive(productRelease);
        return getDataTable(list);
    }
    /**
     * 一键发送终止审核
     */
    @PostMapping("/termination")
    public AjaxResult termination(@RequestBody ProductRelease productRelease){
        return toAjax(productReleaseService.terminationPolicy(productRelease));
    }
}
